package com.xiangban.yanglaodajie_platform.service;


import com.alibaba.fastjson.JSON;
import com.xiangban.yanglaodajie_platform.config.AliYunParameterConfig;
import com.xiangban.yanglaodajie_platform.dao.AccumulatePointsMapper;
import com.xiangban.yanglaodajie_platform.dao.ShopLoginMapper;
import com.xiangban.yanglaodajie_platform.dao.TeacherMapper;
import com.xiangban.yanglaodajie_platform.dao.UserMapper;
import com.xiangban.yanglaodajie_platform.entity.*;
import com.xiangban.yanglaodajie_platform.entity.dto.LoginUserDto;
import com.xiangban.yanglaodajie_platform.entity.dto.RegisterUserDto;
import com.xiangban.yanglaodajie_platform.entity.dto.UserDto;
import com.xiangban.yanglaodajie_platform.entity.res.ApiResultCode;
import com.xiangban.yanglaodajie_platform.entity.vo.AccumulatePointsVo;
import com.xiangban.yanglaodajie_platform.entity.vo.UserApiVo;
import com.xiangban.yanglaodajie_platform.entity.vo.UserVo;
import com.xiangban.yanglaodajie_platform.exception.BizException;
import com.xiangban.yanglaodajie_platform.utils.CommonUtils;
import com.xiangban.yanglaodajie_platform.utils.Md5Utils;
import com.xiangban.yanglaodajie_platform.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.xiangban.yanglaodajie_platform.utils.ALiYunSms.sendSms;
import static com.xiangban.yanglaodajie_platform.utils.CommonUtils.*;
import static com.xiangban.yanglaodajie_platform.utils.RedisUtil.*;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/2/3 11:38
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ShopLoginMapper shopLoginMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private CommonUtils commonUtils;

    @Autowired
    private AliYunParameterConfig aliYunParameterConfig;
    @Autowired
    private OrdersClassOrActivityService ordersClassOrActivityService;
    @Autowired
    private AccumulatePointsMapper accumulatePointsMapper;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private TeacherMapper teacherMapper;

    @Transactional
    public void register(UserVo user) {
        User uVo = new User();
        uVo.setUsername(user.getUsername());
        User userName = userMapper.checkUser(uVo);
        if (userName !=null){
            throw new BizException(ApiResultCode.EXIST_ACCOUNT);
        }
        uVo.setUsername(null);
        uVo.setPhone(user.getPhone());
        User phone = userMapper.checkUser(uVo);
        if (phone !=null){
            throw new BizException(ApiResultCode.EXIST_PHONE);
        }
        if (!checkCode(LoginUserDto.verification_type_register,user.getPhone(),user.getVerification())) {
            throw new BizException(ApiResultCode.FAILED_VERIFICATION);
        }
        String password = user.getPassword();
        user.setPassword(Md5Utils.hash(password));
        user.setCreateTime(new Date());
        userMapper.registerUser(user);
        InvalidVerification(LoginUserDto.verification_type_register,user.getPhone());


    }

    public Map<String,Object> login(LoginUserDto loginUserDto) {
        HashMap<String, Object> res = new HashMap<>();
        if (BizEmpty(loginUserDto.getType())) {
            throw new BizException(ApiResultCode.NULL_LOGIN_TYPE);
        }
        if (loginUserDto.getType() == LoginUserDto.type_account) {
            if (BizEmpty(loginUserDto.getUsername())) {
                throw new BizException(ApiResultCode.NULL_ACCOUNT);
            }
            List<User> userInfo = userMapper.getUserInfo(loginUserDto);
            if (userInfo != null && userInfo.size() > 0) {
                User user = userInfo.get(0);
                //验证密码
                if (CommonUtils.compare(user.getPassword(), Md5Utils.hash(loginUserDto.getPassword()))) {
                    String token = generateToken(user);
                    ArrayList<String> userRoles = getUserRoles(token);
                    UserDto userDto = new UserDto();

                    BeanUtils.copyProperties(userInfo.get(0),userDto);
                    if (userRoles.size()>0){
                        userDto.setRoles(userRoles);
                    }
                    //生成token
                    res.put("token",token);
                    res.put("userInfo",userInfo.get(0));
                    return res;
                }
            }
            throw new BizException(ApiResultCode.FAILED_LOGIN);
        } else {
            if (BizEmpty(loginUserDto.getPhone())) {
                throw new BizException(ApiResultCode.PHONE_NULL);
            }
            List<User> userInfo = userMapper.getUserInfo(loginUserDto);
            if (!checkCode(LoginUserDto.verification_type_login,loginUserDto.getPhone(),loginUserDto.getVerification())) {
                throw new BizException(ApiResultCode.FAILED_VERIFICATION);
            }
            if (userInfo == null || userInfo.size() <= 0) {
                throw new BizException(ApiResultCode.FAILED_ACCOUNT);
            }
            res.put("token",generateToken(userInfo.get(0)));
            res.put("userInfo",userInfo.get(0));
            InvalidVerification(LoginUserDto.verification_type_login,loginUserDto.getPhone());
            return res;
        }
    }

    public Map<String,Object> shopLogin(LoginUserDto loginUserDto) {
        HashMap<String, Object> res = new HashMap<>();
        if (BizEmpty(loginUserDto.getType())) {
            throw new BizException(ApiResultCode.NULL_LOGIN_TYPE);
        }
        List<ShopLogin> shopInfos = shopLoginMapper.getShopInfo(loginUserDto);

        if (loginUserDto.getType() == LoginUserDto.type_account) {
            if (BizEmpty(loginUserDto.getUsername())) {
                throw new BizException(ApiResultCode.NULL_ACCOUNT);
            }
            if (shopInfos != null && shopInfos.size() > 0) {
                ShopLogin shopInfo = shopInfos.get(0);
                //验证密码
                if (CommonUtils.compare(shopInfo.getPassword(), Md5Utils.hash(loginUserDto.getPassword()))) {
                    //生成token
                    res.put("token",generateToken(shopInfo));
                    shopInfo.setPassword(null);
                    res.put("shopInfo",shopInfo);
                    return res;
                }
            }
            throw new BizException(ApiResultCode.FAILED_LOGIN);
        } else {
            if (BizEmpty(loginUserDto.getPhone())) {
                throw new BizException(ApiResultCode.PHONE_NULL);
            }
            if (!checkCode(LoginUserDto.verification_type_login_shop,loginUserDto.getPhone(),loginUserDto.getVerification())) {
                throw new BizException(ApiResultCode.FAILED_VERIFICATION);
            }
            if (shopInfos == null || shopInfos.size() <= 0) {
                throw new BizException(ApiResultCode.FAILED_ACCOUNT);
            }

            res.put("token",generateToken(shopInfos.get(0)));
            res.put("shopInfo",shopInfos.get(0));
            InvalidVerification(LoginUserDto.verification_type_login_shop,loginUserDto.getPhone());
            return res;
        }
    }

    //用户重置密码
    public void resetPassword(LoginUserDto loginUserDto){
        if (BizEmpty(loginUserDto.getPhone())) {
            throw new BizException(ApiResultCode.PHONE_NULL);
        }
        if (BizEmpty(redisUtil.get(LoginUserDto.verification_type_rest_password+loginUserDto.getPhone())) || !loginUserDto.getVerification().equals(redisUtil.get(LoginUserDto.verification_type_rest_password+loginUserDto.getPhone()))) {
            throw new BizException(ApiResultCode.FAILED_VERIFICATION);
        }
        List<User> userInfo = userMapper.getUserInfo(loginUserDto);
        if (userInfo == null || userInfo.size() <= 0) {
            throw new BizException(ApiResultCode.FAILED_ACCOUNT);
        }
        loginUserDto.setPassword(Md5Utils.hash(loginUserDto.getPassword()));
        loginUserDto.setUpdateTime(new Date());
        userMapper.updPassword(loginUserDto);
        InvalidVerification(LoginUserDto.verification_type_rest_password,loginUserDto.getPhone());

    }

    public void resetShopPassword(LoginUserDto loginUserDto){
        if (BizEmpty(loginUserDto.getPhone())) {
            throw new BizException(ApiResultCode.PHONE_NULL);
        }
        if (BizEmpty(redisUtil.get(LoginUserDto.verification_type_rest_password_shop+loginUserDto.getPhone())) || !loginUserDto.getVerification().equals(redisUtil.get(LoginUserDto.verification_type_rest_password_shop+loginUserDto.getPhone()))) {
            throw new BizException(ApiResultCode.FAILED_VERIFICATION);
        }
        List<ShopLogin> shopInfo = shopLoginMapper.getShopInfo(loginUserDto);
        if (shopInfo == null || shopInfo.size() <= 0) {
            throw new BizException(ApiResultCode.FAILED_ACCOUNT);
        }
        loginUserDto.setPassword(Md5Utils.hash(loginUserDto.getPassword()));
        shopLoginMapper.updPassword(loginUserDto);
        InvalidVerification(LoginUserDto.verification_type_rest_password_shop,loginUserDto.getPhone());

    }

    public String generateToken(User user) {
        String newToken = UUID.randomUUID().toString().replace("-", "");
        HashMap<String, Object> loginInfo = new HashMap<>();
        loginInfo.put("time", new Date().getTime());
        loginInfo.put("userId", user.getUserId());
        //获取上次token
        String oldToken = redisUtil.get(fex + user.getUserId());
        //清除上次登录token
        redisUtil.del(fex+oldToken,fex+user.getUserId());
        redisUtil.set(fex + user.getUserId(), newToken, tokenTime);
        redisUtil.set(fex +newToken, JSON.toJSONString(loginInfo), tokenTime);
        return newToken;
    }

    public String generateToken(ShopLogin shopLogin) {
        String newToken = UUID.randomUUID().toString().replace("-", "");
        HashMap<String, Object> loginInfo = new HashMap<>();
        loginInfo.put("time", new Date().getTime());
        loginInfo.put("shopId", shopLogin.getShopId());
        //获取上次token
        String oldToken = redisUtil.get(fex_shop + shopLogin.getShopId());
        //清除上次登录token
        redisUtil.del(fex_shop+oldToken,fex_shop+shopLogin.getShopId());
        redisUtil.set(fex_shop + shopLogin.getShopId(), newToken, tokenTime);
        redisUtil.set(fex_shop +newToken, JSON.toJSONString(loginInfo), tokenTime); //存储登陆信息
        return newToken;
    }

    /**
     *
     * @param verification_type 验证码类型
     * @param phone 手机号
     * @param code 验证码
     * @return
     */
    public boolean checkCode(String verification_type,String phone,String code){
        String code1 = redisUtil.get(verification_type + phone);
        return !BizEmpty(code1) && code.equals(code1);
    }




    public List<Object> registerInfo(Map<String,Integer> map) {
//        Map<String, List<String>> infoMap = new HashMap<String, List<String>>();
//        List<String> aihao = new ArrayList<>();
//        aihao.add("写作（小说、诗歌、散文）");
//        aihao.add("阅读");
//        aihao.add("摄影");
//        aihao.add("书法");
//        aihao.add("绘画（国画、油画、水彩、版画、卡通画、年画）");
//        aihao.add("视频编辑");
//        aihao.add("声乐（作词、作曲、通俗、美声）");
//        aihao.add("舞蹈（民族舞、古典舞、现代舞）");
//        aihao.add("戏曲（沪剧、越剧、昆曲、京剧、黄梅戏、锡剧、评弹）");
//        aihao.add("乐器（二胡、钢琴、电子琴、杨琴、手风琴、口琴、管乐、葫芦丝、琵琶）");
//        aihao.add("美食（西餐、中餐、小吃）");
//        aihao.add("旅游");
//        aihao.add("收藏（字画、玉器、家具）");
//        aihao.add("时装");
//        aihao.add("美容");
//        aihao.add("养生");
//        aihao.add("设计（工业、工程、家装、平面、服装、形象）");
//        List<String> xuqiu = new ArrayList<>();
//        xuqiu.add("理发");
//        xuqiu.add("家电维修（电视、电脑、洗衣机、冰箱、空调、热水器）");
//        xuqiu.add("水电（安装、维修）");
//        xuqiu.add("修脚");
//        xuqiu.add("助浴");
//        xuqiu.add("推拿");
//        xuqiu.add("按摩");
//        xuqiu.add("做饭");
//        xuqiu.add("洗衣");
//        xuqiu.add("保洁");
//        xuqiu.add("陪护");
//        infoMap.put("aihao", aihao);
//        infoMap.put("xuqiu", xuqiu);
//        return infoMap;
        List<Object> list = userMapper.choiceHobby(map);
        return list;
    }

    /**
     * 解析 user 对象
     *
     * @param
     * @return
     */
    private User parseToUser(RegisterUserDto registerUserDto) {
        if (!registerUserDto.getUsername().isEmpty() && !registerUserDto.getPassword().isEmpty() && !registerUserDto.getPhone().isEmpty()) {
            User user = new User();
            registerUserDto.setPassword(CommonUtils.MD5(registerUserDto.getPassword()));
            BeanUtils.copyProperties(registerUserDto, user);
            user.setCreateTime(new Date());
            user.setImage(getRandomImg());
            user.setStatus(1);
            return user;
        } else {
            return null;
        }
    }

    /**
     * 放在 CDN 上的随机头像
     */
    private static final String[] headImg = {
            "https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=276772730,3789231562&fm=26&gp=0.jpg",
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=348404915,2991827248&fm=26&gp=0.jpg",
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1624413897,3529421674&fm=26&gp=0.jpg"
    };

    private String getRandomImg() {
        int s = headImg.length;
        Random random = new Random();
        int i = random.nextInt(s);//0-s任意一个
        return headImg[i];
    }


    /**
     * 获取验证码
     *
     * @param loginUserDto
     */
    public void verification(LoginUserDto loginUserDto) {
        HashMap<String, Object> smsParameter = new HashMap<>();
        if (BizEmpty(loginUserDto.getPhone())) {
            throw new BizException(ApiResultCode.PHONE_NULL);
        }
        if (BizEmpty(loginUserDto.getVerificationType())){
            throw new BizException(ApiResultCode.PARAMETER_DEFICIENCY);
        }
        String code = RandomStringUtils.randomNumeric(6);
        smsParameter.put("code",code);
        if (common_1.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_login + loginUserDto.getPhone();
            redisUtil.set(key, code , codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getLoginCodeTemplate(),loginUserDto.getPhone(),smsParameter);
        }
        else if (common_2.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_register + loginUserDto.getPhone();
            redisUtil.set(key, code, codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getRegisterTemplate(),loginUserDto.getPhone(),smsParameter);

        }
        else if (common_3.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_rest_password + loginUserDto.getPhone();
            redisUtil.set(key, code, codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getResetPasswordTemplate(),loginUserDto.getPhone(),smsParameter);
        }
        else if (common_4.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_login_shop + loginUserDto.getPhone();
            redisUtil.set(key, code , codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getLoginCodeTemplate(),loginUserDto.getPhone(),smsParameter);
        }
        else if (common_5.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_register_shop + loginUserDto.getPhone();
            redisUtil.set(key, code, codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getRegisterTemplate(),loginUserDto.getPhone(),smsParameter);
        }
        else if (common_6.equals(loginUserDto.getVerificationType())){
            String key = LoginUserDto.verification_type_rest_password_shop + loginUserDto.getPhone();
            redisUtil.set(key, code, codeTime);
            InvalidVerification(key,loginUserDto.getPhone());
            sendSms(aliYunParameterConfig.getResetPasswordTemplate(),loginUserDto.getPhone(),smsParameter);
        }
        else {
            throw new BizException(ApiResultCode.PARAMETER_EXCEPTION);
        }
        log.info("手机号：" + loginUserDto.getPhone() + "\n验证码是:" + code);
    }

    public void logout() {
        String token = request.getHeader("token");
        String userInfo = redisUtil.get(fex+"token");
        Map<String,String> map = (Map<String, String>) JSON.parse(userInfo);
        if (map!=null){
            String userId = map.get("userId");
            redisUtil.del(fex+userId,fex+token);
        }
    }

    public UserDto getUserInfo() {
        UserDto user = new UserDto();
        String userId = commonUtils.getUserId(request);
        String token = request.getHeader("token");
        if (userId == null) {
            return null;
        }
        user.setUserId(Integer.parseInt(userId));
        UserDto userInfo = userMapper.getUserInfoById(user);
        ArrayList<String> userRoles = getUserRoles(token);
//        if (userRoles.size()>0){
            userInfo.setRoles(userRoles);
//        }

        ClassSign classSign = new ClassSign();
        classSign.setUserId(Integer.parseInt(userId));
        int signLongTime = ordersClassOrActivityService.getSignLongTime(classSign);
        userInfo.setLongTime(signLongTime);
        String hobby = userInfo.getHobby();
        List arr = JSON.parseArray(hobby);
        System.out.print(arr);
        List hobbyById = userMapper.getHobbyById(arr);
        userInfo.setInterest(hobbyById.get(0));
        userInfo.setHobbyName(hobbyById.get(1));
        return userInfo;
    }

    //登录后获角色
    public ArrayList<String> getUserRoles(String token){
        ArrayList<String> roles = new ArrayList<>();
        if (BizEmpty(token)){
            return roles;
        }
        String userId = commonUtils.getUserIdByToken(token);
        UserDto user = new UserDto();
        user.setUserId(Integer.parseInt(userId));
        UserDto userInfo = userMapper.getUserInfoById(user);
        Teacher teacher = new Teacher();
        teacher.setPhone(userInfo.getPhone());
        teacher.setStates(0);
        //获取教师id
        List<Teacher> teacherList = teacherService.getClassByPhone(teacher);
        if (teacherList.size()>0){
            //根据老师获取所带的班级
            List<TeacherShop> bindClassByTeacher = teacherService.getBindClassByTeacher(teacherList);
            if (bindClassByTeacher.size()>0){
                roles.add(UserDto.teacher);
            }
        }
        //获取教务人员信息
        TeacherLeader teacherLeader = new TeacherLeader();
        teacherLeader.setPhone(userInfo.getPhone());
        teacherLeader.setStatus(0);
        List<TeacherLeader> teacherLeaderList = teacherMapper.getTeacherLeaderList(teacherLeader);
        if (teacherLeaderList.size()>0){
            roles.add(UserDto.teacher_leader);

        }

        return roles;
    }


    /**
     * 失效验证码
     * @param type 验证码类型
     * @param phone 用户手机号
     */
    public void InvalidVerification(String type,String phone){
        redisUtil.del(type+phone);
    }

    /**
     * 修改用户信息
     * @param
     */
    public void updateUserInfo(UserDto userDto) {
        User user = new User();
        BeanUtils.copyProperties(userDto,user);
        user.setUserId(Integer.parseInt(commonUtils.getUserId(request)));
        User user1 = userMapper.selectById(user.getUserId());
        if (BizEmpty(user1)){
            throw new BizException(ApiResultCode.FAILED_ACCOUNT);
        }
        user.setUpdateTime(new Date());
        userMapper.updateById(user);
    }

    //***************************平台交互************************************
    public void addUser(UserApiVo user) {
        User uVo = new User();
        uVo.setUsername(user.getUsername());
        User userName = userMapper.checkUser(uVo);
        if (userName !=null){
            throw new BizException(ApiResultCode.EXIST_ACCOUNT);
        }
        uVo.setUsername(null);
        uVo.setPhone(user.getMobile());
        User phone = userMapper.checkUser(uVo);
        if (phone !=null){
            throw new BizException(ApiResultCode.EXIST_PHONE);
        }
//        UserVo userVo = new UserVo();
//        userVo.setUsername(user.getUsername());
//        userVo.setNickName(user.getNickname());
//        userVo.setImage(user.getImage());
//        userVo.setPhone(user.getMobile());
//        userVo.setPassword(Md5Utils.hash(user.getMobile()));
//        userVo.setSex(user.getSex().toString());
//        userVo.setCardNo(user.getCardNo());
//        String hobby = "[,]";
//        userVo.setHobby(hobby);
//        userVo.setCreateTime(new Date());
//        userVo.setStatus(1);
//        userVo.setOpenId(user.getOpenId());
        UserVo userVo = interactionUser(user);
        userMapper.registerUser(userVo);
    }

    public void updateUser(UserApiVo user) {
        if (BizEmpty(user.getUserId())){
            throw new BizException(ApiResultCode.PARAMETER_DEFICIENCY);
        }

        UserDto userDto = new UserDto();
        userDto.setUserId(Integer.parseInt(user.getUserId()));
//        UserDto userInfoById = userMapper.getUserInfoById(userDto);
//        if (BizEmpty(userInfoById)){
//            throw new BizException(ApiResultCode.FAILED_ACCOUNT);
//        }
        user.setPassword(user.getSex().toString());
        user.setUpdateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        userMapper.updateUser(user);
    }

    public UserVo interactionUser(UserApiVo user){
        UserVo userVo = new UserVo();
        userVo.setUsername(user.getUsername());
        userVo.setNickName(user.getNickname());
        userVo.setImage(getRandomImg());
        userVo.setPhone(user.getMobile());
        userVo.setPassword(Md5Utils.hash(user.getMobile()));
        userVo.setSex(user.getSex().toString());
        userVo.setCardNo(user.getCardNo());
        String hobby = "[16,27]";
        userVo.setHobby(hobby);
        userVo.setCreateTime(new Date());
        userVo.setStatus(1);
        userVo.setOpenId(user.getOpenId());
        return userVo;
    }


    public void updateAccumulatePoints(UserApiVo user) {
        AccumulatePointsVo accumulatePointsVo = new AccumulatePointsVo();
        accumulatePointsVo.setId(Integer.parseInt(user.getLeaderId()));//唯一值
        accumulatePointsVo.setPhone(user.getMobile());
        accumulatePointsVo.setAccumulatePoints(user.getEatPoint());

        AccumulatePointsVo logById = accumulatePointsMapper.findLogById(accumulatePointsVo);//利用唯一值，查询有没有变更记录
        if (logById == null){
            accumulatePointsMapper.saveLog(accumulatePointsVo);//把每次传来的值记录进去
        }else {
            accumulatePointsMapper.updateScore(accumulatePointsVo);//修改分数
        }
        //计算出每次加了多少积分
        BigDecimal subtract = accumulatePointsVo.getAccumulatePoints().subtract(logById.getAccumulatePoints());

        User userByPhone = userMapper.findUserByPhone(user);

        String orderNo = getOrderNo();//生成订单编号
        AccumulatePoints accumulatePoints = new AccumulatePoints();
        accumulatePoints.setUserId(userByPhone.getUserId());
        accumulatePoints.setAccumulatePoints(subtract);
        accumulatePointsMapper.updateAP(accumulatePoints);//变更积分
        accumulatePoints.setPayState(0);
        accumulatePoints.setType(1);
        accumulatePoints.setOrderNumber(orderNo);
        accumulatePoints.setDescribe("志愿者积分");
        accumulatePoints.setRecodeType(4);
        accumulatePointsMapper.saveAP(accumulatePoints);//插入积分记录
    }

}
